import React, { Component } from 'react';
// import {Styless} from "./logins"

class Login extends Component {
    state={
        username:{
            value:"",
            onChange:(e)=>{this.setState(state=>state.username.value=e.target.value.trim())}
        },
        pwd:{
            value:"",
            onChange:(e)=>{this.setState(state=>state.pwd.value=e.target.value.trim())}
        }
    }
    login=()=>{
        // 获取用户账号信息
        // let obj = {username:this.state.username.value,pwd:this.state.pwd.value}
        // localStorage.setItem("user",JSON.stringify(obj))
        // 设置token和用户名
        if(this.state.username.value!==""&&this.state.pwd.value!==""){
            let token = {username:this.state.username.value,token:"99999999"}
            localStorage.setItem("token",JSON.stringify(token))
            // 点赞数组
            let like = []
            localStorage.setItem(("like"),JSON.stringify(like))
            // 收藏数组
            let collect = []
            localStorage.setItem(("collect"),JSON.stringify(collect))
            this.props.history.go(-1)
        }else{
            alert("请认真填写")
        }
    }

    render() {
        let {username,pwd} = this.state
        return (
            <div>
                <div>
                    <label>
                        用户名：
                        <input type="text" {...username}  />
                    </label>
                </div>
                <div>
                    <label>
                        密&nbsp;&nbsp;&nbsp;码：
                        <input type="password" {...pwd} />
                    </label>
                </div>
                <button onClick={()=>this.login()}>登录</button>
            </div>
        );
    }
}

export default Login;
